{% extends 'base.html.twig' %}
{% import 'Import/app_import.html.twig' as appImport %}

{% block head_title %}{{ 'elasticsearch_roles'|trans }} - {{ role.name }}{% endblock %}

{% block heading_1 %}
    {{ appImport.heading({'level': 1, 'title': 'elasticsearch_roles'|trans, 'link': {'url': path('elasticsearch_roles')}}) }}
{% endblock %}

{% block heading_2 %}
    {{ appImport.heading({'level': 2, 'title': role.name}) }}
{% endblock %}

{% block tabs %}
    {% include 'Modules/role/role_read_tabs.html.twig' with {'active': 'summary'} %}
{% endblock %}

{% block main_content %}
    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.heading({'level': 3, 'title': 'summary'|trans}) }}

            {% embed 'Embed/buttons_embed.html.twig' %}
                {% import 'Import/app_import.html.twig' as appImport %}
                {% block content %}
                    {% if is_granted('ELASTICSEARCH_ROLE_DELETE', role) %}
                        {{ appImport.buttonModal({
                            'id': 'RoleDelete',
                            'title': 'delete'|trans,
                            'body': role.name,
                            'href': path('elasticsearch_roles_delete', {'role': role.name}),
                        }) }}
                    {% endif %}

                    {% if is_granted('ELASTICSEARCH_ROLE_COPY', role) %}
                        <a class="btn btn-primary btn-sm" href="{{ path('elasticsearch_roles_create', {'role': role.name}) }}">{{ 'copy'|trans }}</a>
                    {% endif %}
                {% endblock %}
            {% endembed %}

            <div class="row">
                <div class="col-12 col-md-5 col-lg-4">
                    <p>
                        <strong>{{ 'reserved'|trans }}</strong><br>
                        {% if role.isReserved %}
                            {{ appImport.badge({'title': 'boolean.true'|trans, 'context': 'true'}) }}
                        {% else %}
                            {{ appImport.badge({'title': 'boolean.false'|trans, 'context': 'false'}) }}
                        {% endif %}
                    </p>

                    <p>
                        <strong>{{ 'deprecated'|trans }}</strong><br>
                        {% if role.isDeprecated %}
                            {{ appImport.badge({'title': 'boolean.true'|trans, 'context': 'true'}) }}
                        {% else %}
                            {{ appImport.badge({'title': 'boolean.false'|trans, 'context': 'false'}) }}
                        {% endif %}
                    </p>

                    {% if role.isDeprecated and role.deprecatedReason %}
                        <p>
                            <strong>{{ 'deprecated_reason'|trans }}</strong><br>
                            {{ role.deprecatedReason }}
                        </p>
                    {% endif %}
                </div>

                {% if role.metadata and 0 < role.metadata|length %}
                    <div class="col-12 col-md-5 col-lg-4">
                        <p>
                            <strong>{{ 'metadata'|trans }}</strong><br>
                            <pre>{{ role.metadata|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
                        </p>
                    </div>
                {% endif %}
            </div>

            {% if role.cluster and 0 < role.cluster|length %}
                {{ appImport.heading({'level': 4, 'title': 'cluster'|trans}) }}

                {% embed 'Embed/table_embed.html.twig' %}
                    {% block thead %}
                        <tr>
                            <th>{{ 'privileges'|trans }}</th>
                        </tr>
                    {% endblock %}

                    {% block tbody %}
                        {% for record in role.cluster %}
                            <tr>
                                <td>{{ record }}</td>
                            </tr>
                        {% endfor %}
                    {% endblock %}
                {% endembed %}
            {% endif %}

            {% if role.runAs and 0 < role.runAs|length %}
                {{ appImport.heading({'level': 4, 'title': 'run_as'|trans}) }}

                {% embed 'Embed/table_embed.html.twig' %}
                    {% block thead %}
                        <tr>
                            <th>{{ 'privileges'|trans }}</th>
                        </tr>
                    {% endblock %}

                    {% block tbody %}
                        {% for record in role.runAs %}
                            <tr>
                                <td>{{ record }}</td>
                            </tr>
                        {% endfor %}
                    {% endblock %}
                {% endembed %}
            {% endif %}

            {% if role.indices and 0 < role.indices|length %}
                {{ appImport.heading({'level': 4, 'title': 'indices'|trans}) }}

                {% embed 'Embed/table_embed.html.twig' %}
                    {% block thead %}
                        <tr>
                            <th>{{ 'names'|trans }}</th>
                            <th>{{ 'privileges'|trans }}</th>
                        </tr>
                    {% endblock %}

                    {% block tbody %}
                        {% for record in role.indices %}
                            <tr>
                                <td>{{ record['names']|join('<br>')|raw }}</td>
                                <td>{{ record['privileges']|join('<br>')|raw }}</td>
                            </tr>
                        {% endfor %}
                    {% endblock %}
                {% endembed %}
            {% endif %}

            {% if role.applications and 0 < role.applications|length %}
                {{ appImport.heading({'level': 4, 'title': 'applications'|trans}) }}

                {% embed 'Embed/table_embed.html.twig' %}
                    {% block thead %}
                        <tr>
                            <th>{{ 'application'|trans }}</th>
                            <th>{{ 'privileges'|trans }}</th>
                            <th>{{ 'resources'|trans }}</th>
                        </tr>
                    {% endblock %}

                    {% block tbody %}
                        {% for record in role.applications %}
                            <tr>
                                <td>{{ record['application'] }}</td>
                                <td>{{ record['privileges']|join('<br>')|raw }}</td>
                                <td>{{ record['resources']|join('<br>')|raw }}</td>
                            </tr>
                        {% endfor %}
                    {% endblock %}
                {% endembed %}
            {% endif %}
        {% endblock %}
    {% endembed %}
{% endblock %}
